package basicCompiler;

import java.util.Stack;

import basicCompiler.visitor.AbstractTreeVisitor;
import basicCompiler.visitor.TreeVisitable;

public abstract class AbstractOperator extends Node implements Comparable<AbstractOperator>,  TreeVisitable{
	String value;
	protected int priority;
	
	public AbstractOperator(){
		super();
		this.priority = 0;
	}
	
	public AbstractOperator(String exp){
		this();
		this.value = exp;
	}
	
	protected void setPriority(int value){
		this.priority = value;
	}
	
	public int compareTo(AbstractOperator op){
		if (op == null)
			throw new NullPointerException();
		/* TODO: not sure if needed
		if (! (op instanceof AbstractOperator))
			throw new ClassCastException();
		*/
		return this.priority - op.priority;
	}
	
	public String toString(){
		return value;
	}
	
	public void accept(AbstractTreeVisitor v, Stack<Node> results, Stack<AbstractOperator> operators){
		v.visit(this, results, operators);
	}
}



class EqualsOperator extends AbstractOperator {

	public EqualsOperator(String exp) {
		super( exp);
	}	
}

class OrOperator extends AbstractOperator {
	
	public OrOperator(String exp) {
		super( exp);
		super.setPriority(1);
	}	
}

class AndOperator extends AbstractOperator {
	
	public AndOperator(String exp) {
		super( exp);
		super.setPriority(2);
	}	
}

